#!/bin/bash

echo "=== 子模块下载重试脚本 ==="

cd /d/vc/wxWidgets

MAX_RETRIES=3
SUBMODULES=(
    "src/expat"
    "src/png" 
    "src/zlib"
    "src/jpeg"
    "src/tiff"
    "3rdparty/catch"
    "3rdparty/libwebp"
    "3rdparty/nanosvg"
    "3rdparty/pcre"
    "src/stc/lexilla"
    "src/stc/scintilla"
)

for submodule in "${SUBMODULES[@]}"; do
    retry_count=0
    while [ $retry_count -lt $MAX_RETRIES ]; do
        echo "尝试下载: $submodule (尝试 $((retry_count + 1))/$MAX_RETRIES)"
        if git submodule update --init "$submodule"; then
            echo "✅ $submodule 下载成功"
            break
        else
            echo "❌ $submodule 下载失败"
            ((retry_count++))
            if [ $retry_count -eq $MAX_RETRIES ]; then
                echo "⚠️  $submodule 达到最大重试次数，跳过"
            else
                echo "等待 2 秒后重试..."
                sleep 2
            fi
        fi
    done
    echo ""
done

echo "=== 最终状态 ==="
git submodule status
